import React from 'react';
import { Button } from 'antd';
import { WeaTab, WeaLocaleProvider } from 'ecCom';
import { WeaTableNew } from 'comsMobx';
import { TaskListType, TaskViewUrl } from '../../../constants/task';
import route from '../../../constants/route';
import { observer } from 'mobx-react';
import Condition from './Condition';
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class TaskList extends React.Component {
    componentDidMount() {
        window.openEdcTaskFromTaskList = this.openTask
        window.openEdcTaskViewFromTaskList = this.openTaskView
    }
    openTask = (id, nodeid) => {
        const width = screen.availWidth - 10;
        const height = screen.availHeight - 50;
        let szFeatures = "";
        szFeatures = "top=0,left=0,";
        szFeatures += "width=" + width + ",";
        szFeatures += "height=" + height + ",";
        szFeatures += "directories=no,status=yes,toolbar=no,location=no,";
        szFeatures += "menubar=no,scrollbars=yes,resizable=yes";
        window.open(`${TaskViewUrl}#/${route.view}?taskid=${id}&nodeid=${nodeid}&userid=${this.props.params.userid || ''}`, "", szFeatures);
    }
    openTaskView = (id) => {
        const width = screen.availWidth - 10;
        const height = screen.availHeight - 50;
        let szFeatures = "";
        szFeatures = "top=0,left=0,";
        szFeatures += "width=" + width + ",";
        szFeatures += "height=" + height + ",";
        szFeatures += "directories=no,status=yes,toolbar=no,location=no,";
        szFeatures += "menubar=no,scrollbars=yes,resizable=yes";
        window.open(`${TaskViewUrl}#/${route.view}?taskid=${id}&userid=${this.props.params.userid || ''}`, "", szFeatures);
    }
    render() {
        const { store } = this.props;
        const { tableStore } = store;
        return (
            <div className="edc-task-list">
                <WeaTab
                    datas={TaskListType}
                    counts={store.topCount}
                    keyParam="key"  //主键
                    countParam="key"
                    selectedKey={store.selectedTab}
                    searchType={['base', 'advanced']}
                    onChange={store.changeTab}
                    onSearch={store.quickSearch}
                    onSearchChange={store.changeQuickSearchValue}
                    searchsBaseValue={store.quickSearchValue}

                    showSearchAd={store.conditionVisible}
                    setShowSearchAd={store.setConditionVisible}
                    buttonsAd={this.getConditionButtons()}
                    searchsAd={<Condition store={store} />}
                />
                <WeaTable comsWeaTableStore={tableStore} needScroll={true} hasOrder={true} register_table={store.reloadTable} uniqueId={true} />
            </div>
        )
    }
    getConditionButtons = () => {
        const { store } = this.props;
        return [
            (<Button type="primary" onClick={store.search}>{getLabel(388113, '搜索')}</Button>),
            (<Button type="ghost" onClick={store.clearCondition}>{getLabel(2022, '重置')}</Button>),
            (<Button type="ghost" onClick={store.setConditionVisible.bind(this, false)}>{getLabel(31129, '取消')}</Button>)
        ]
    }

}